;; Define a function that takes a list and returns a list indicating
;; the number of times each (eql) element appears, sourted from most
;; common element to least common:
;; > (occurrences '(a b a d a c d c a))
;; ((A . 4) (C . 2) (D . 2) (B . 1))

;(defun occurrences (lst)
 ; (count (car lst) (cdr lst))

;(defun count (ele lst)
;  ())

(defun short-length (lst)
  (let ((lst-cp (copy-list lst))
	(result nil))
    (if (null lst-cp)
	nil
	(progn
	  (setf result (append (short-first-ele lst-cp) result nil))
	  (append result (short-first-ele (remove (car lst-cp) lst-cp)) nil)))))
	


;get the times that the first element of a list apears
(defun short-first-ele (lst)
  (if (null lst)
      nil
      (let ((first-ele (car lst))
	    (next (cdr lst)))
	(cons first-ele (find-times first-ele 1 next)))))
	    

;find the times that ele apears in the lst, 
(defun find-times (ele times lst)
  (if (null lst)
      times
      (let ((next (member ele lst)))
	(if (not next)
	    times
	    (progn
	      (setf times (+ times 1))
	      (find-times ele times (cdr next)))))))

    	

